#!/bin/sh

LOG="echo SYSLOG"

start() {
    get_param
    if [ "$KLogd" != "0" ] && [ "$KLogd" != "" ]; then
	$LOG "Start klogd"
	klogd &
    fi

    if [ "$SysLogd" != "0" ] && [ "$SysLogd" != "" ]; then
	if [ "$RemoteSysLogIP" != "0.0.0.0" ] && [ "$RemoteSysLogIP" != "" ]; then
	    $LOG "Start syslogd remote mode. Host $RemoteSysLogIP"
	    syslogd -b0 -s40 -l7 -R $RemoteSysLogIP -D &
	else
	    $LOG "Start syslogd local"
	    syslogd -b0 -s40 -l7 -S -D &
	fi
    fi
}

get_param() {
    eval `nvram_buf_get 2860 KLogd SysLogd RemoteSysLogIP`
}

stop() {
 $LOG "Stop syslog and klog"
    killall -q klogd
    killall -q -SIGKILL klogd
    killall -q syslogd
    killall -q -SIGKILL syslogd
    rm -f /var/log/messages > /dev/null 2>&1
}

case "$1" in
	start)
	    start
	    ;;

	stop)
	    stop
	    ;;

	restart)
	    stop
	    start
	    ;;

	*)
	    echo $"Usage: $0 {start|stop|restart}"
	    exit 1
esac
